<template>
  <div>
    <el-button @click="querydept()"></el-button>
  </div>
</template>

<script>
import { getmenulist } from "@/api/menu";
import { asyncRoutes, constantRoutes } from "@/router";
import Layout from "@/layout";

export default {
  data() {
    return {
      data: []
    };
  }, //网页加载事件
  mounted: function() {
    this.querydept();
    console.log(this.menu);
  },
  methods: {
    querydept() {
      getmenulist().then(response => {
        let data = response.data;
        console.log(data);

        data.forEach(function(item, index) {
          console.log(item);
          const menu = {
            path: item.path === "#" ? item.menuId + "_key" : item.path,
            component:
              item.component === "#"
                ? Layout
                : () => import(`@/views${item.path}/index`),
            // hidden: true,
            children: item.children,
            name: "menu_" + item.menuId,
            meta: { title: item.menuName, id: item.menuId, roles: ["admin"] }
          };
        });

        data.forEach(item => {
          // alert(JSON.stringify(item))
          console.log(item);
          console.log(item.menuId);
          const menu = {
            // path: item.path,

            // component:
            //   item.component === "#"
            //     ? Layout
            //     : () => import(`@/views${item.path}/index`),
            // hidden: true,
            // hidden: true,
            // children: item.children,
            // name: item.menuName,
            // meta: { title: item.menuName }

            path: item.path === "#" ? item.menuId + "_key" : item.path,
            component:
              item.component === "#"
                ? Layout
                : () => import(`@/views${item.path}/index`),
            // hidden: true,
            children: [],
            name: "menu_" + item.menuId,
            meta: { title: item.menuName, id: item.menuId, roles: ["admin"] }
          };
          console.log(menu);
          if (item.children) {
            generaMenu(menu.children, item.children);
          }
          routes.push(menu);
        });
      });
    }
  }
};
</script>

<style lang="scss" scoped>
</style>